<template>
  <div>
    <div class="imageisull">
      <div v-if="this.typedt == 1">河类五</div>
      <div v-else>澳洲五</div>
      <div>第
         
         <input v-model="numIss" style="width:180px" type="text">
         期</div>
     
      <div class="statusIsu">未开奖</div>
      <div class="statusIsu">
        <el-checkbox v-model="isWin">中奖</el-checkbox>
      </div>
       <div class="statusIsu">
        <el-button @click.native="toMore" size="mini" type="primary">确定</el-button>
      </div>
    </div>
    <div class="list">
      <el-table
        class="tables"
        border
        size="mini"
        :header-cell-style="{background:'#ccc'}"
        :data="list"
        stripe
        style="width: 100%"
        show-summary
        :summary-method="getSummaries"
      >
        <el-table-column prop="module" label="彩种"></el-table-column>
        <el-table-column prop="issue" label="期数"></el-table-column>
        <el-table-column prop="orderId" label="注单编号"></el-table-column>
        <el-table-column prop="createTime" label="下注时间"></el-table-column>
        <el-table-column prop="num" label="号码"></el-table-column>
        <el-table-column prop="itemAmount" label="金额"></el-table-column>
        <el-table-column prop="odds" label="赔率"></el-table-column>
        <el-table-column prop="winAmount" label="中奖"></el-table-column>
        <el-table-column prop="backAmount" label="回水"></el-table-column>
        <el-table-column prop="profit" label="盈亏"></el-table-column>
        <el-table-column prop="statusName" label="状态"></el-table-column>
        <el-table-column>
          <template slot-scope="scope">
            <el-button
              v-if="scope.row.status==1?true:false"
              @click.native="toBack(scope.row)"
              size="mini"
              type="primary"
            >退码</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      style="float:right;padding-bottom:30px;margin-top:20px"
      :current-page.sync="curpages"
      :pager-count="5"
      @current-change="fy"
      :page-size="100"
      background
      layout="prev, pager, next"
      :total="total"
    ></el-pagination>
  </div>
</template>
<script>
import { mapState } from "Vuex";
export default {
  data() {
    return {
      // msg: {},
      isWin: "",
      list: [],
      pages: 1,
      total: 10,
      numIss: this.$route.query.issue,
      curpages: 1
    };
  },
  created() {
    console.log(this.$route.query.issue);
    if (this.$route.query.issue == undefined) {
      this.numIss = this.issus.issue;
      this.getList();
    } else {
      this.numIss = this.$route.query.issue;
      this.getList();
    }
    console.log(this.numIss, 88899900);
  },
  computed: {
    ...mapState(["typedt", "issus"])
  },
  watch: {
    // typedt() {
    //   this.getCur();
    // },
    // isWin() {
    //   this.getCur();
    // }
  },
  methods: {
    // 更新接口
      automatic(){
       this.$api.post(
        this.$url.getInfo,
        {},
        res => {
          console.log(res.data,"余额刷新")
          if (res.data.code == 200) {
            this.$store.commit("getUserMsg", JSON.stringify(res.data.data));
          }else{
            this.$message.error(res.data.msg);
          }
        }
      );
    },
    toBack(val) {
      // debugger
      this.$api.post(
        this.$url.cancel,
        {
          ids: val.orderId,
          module: this.typedt
        },
        res => {
          // debugger     
          if (res.data.code == 200) {
            // this.userMsg.balance = this.userMsg.balance + val.itemAmount;
            // this.$store.commit("getUserMsg", JSON.stringify(this.userMsg));
          this.$message({
            message: "退码成功",
            type: "success"
          });
            this.automatic();
            
            this.getList();  
             this.$router.go(0);
           
          }else{
            this.$message.error(res.data.msg);
          }
        }
      );
    },
    toMore() {
      this.pages = 1;
      this.curpages = 1;
      this.getList();
    },
    fy(val) {
      this.pages = val;
      this.getList();
    },
    getList() {
      var winType;
      if (this.isWin) {
        winType = 1;
      } else {
        winType = 0;
      }
      var params = {
        pageNum: this.pages,
        pageSize: 100,
        module: this.typedt,
        issue: this.numIss,
        isWin: winType
      };
      this.$api.post(this.$url.detail, params, res => {
        console.log(res.data, "详情");
        if (res.data.code == 200) {
          this.total = res.data.count;
          this.list = res.data.data;
        }
      });
    },
    getSummaries(param) {
      const { columns, data } = param;
      const sums = [];
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = "总价";
          return;
        }
        const values = data.map(item => Number(item[column.property]));
        if (!values.every(value => isNaN(value))) {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr);
            if (!isNaN(value)) {
              return prev + curr;
            } else {
              return prev;
            }
          }, 0);
          sums[index] += " 元";
        } else {
          sums[index] = "";
        }
      });
      sums[1] = "";
      return sums;
    }
  }
};
</script>
<style lang="less" scope>
.imageisull {
  display: flex;
  align-items: center;
  .statusIsu {
    margin-left: 20px;
  }
}
.list {
  margin-top: 20px;
}
</style>